using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
using Dapr.Client;
using EasyDapr.Infrastructure.App.Dtos;
using EasyDapr.Infrastructure.App.Requests.Identity;
using EasyDapr.Infrastructure.Response;
using InventoryService.Application.Requests;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace InventoryService.Api.Controllers
{
    [ApiController]
    public class InventoryDaprController : ControllerBase
    {
        [HttpGet("get-by-id")]
        public async Task<ApiResult<InventoryDto>> GetById([FromServices] IMediator mediator, [Required] string id)
        {
            var request = new GetInventoryRequest(id);
            var rsp = await mediator.Send(request);
            return rsp;
        }

        [HttpGet("get-user-by-id")]
        public async Task<UserDto> GetUserById(
            [FromServices] DaprClient client, [Required] string id, CancellationToken cancellationToken = default)
        {
            var requestData = new UserByIdRequest {UserId = id};
            var rsp = await client.InvokeMethodAsync<UserByIdRequest, UserDto>(
                "identity-app",
                "get-user-by-id",
                requestData,
                cancellationToken: cancellationToken);
            return rsp;
        }
    }
}